<!DOCTYPE html>
<html lang="en">
<title>企业储值卡管理</title>
<#import "/layout/layout.html" as body/>

<@body.page>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title overflow">
                        <h5 class="pull-left">验证企业</h5>
                    </div>
                    <div class="ibox-content">
                        <form method="post" enctype="multipart/form-data" class="form-horizontal"
                                name="addCard" id="addCard" action="#">
                            <input type="hidden" id="id" value="${id!}">
                            <div class="form-group"><h2 class="col-sm-12 margin-top">Step2:内部验证</h2></div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group"><label class="col-sm-2 control-label">选择验证人</label>
                                <div class="col-sm-10" id="users">
                                    <!--<div class="checkbox-inline i-checks"><label for="is_user3"> <input type="radio" checked id="is_user3" value="188 8888 0000" name="a"> <i></i> 波波 </label></div>-->
                                    <#if checkList??>
                                        <#list checkList as list>
                                            <div class="checkbox-inline i-checks"><label for="${list.id!}"> <input type="radio" id="${list.id!}" value="${list.phone!}" name="a" data-name="${list.name!}"> <i></i> ${list.name!} </label></div>
                                        </#list>
                                    </#if>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">发送验证码</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="mobile"style="width: 130px;float: left; border: 0" readonly>
                                    <input id="sendCheckCode" type="button" class="btn btn-sm btn-primary btn-rounded" value="发送验证码">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group"><label class="col-sm-2 control-label">输入验证码</label>
                                <div class="col-sm-10"><input id="checkCode" class="form-control" placeholder="联系验证人得到验证码"></div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </form>
                    </div>
                    <div class="ibox-content overflow">
                        <div class="col-sm-12">
                            <a href="${baseUrl}system/company/add_step1?id=${id!}" class="btn btn-default pull-left">返回上一步</a>
                            <button id="submit" type="button" class="btn btn-primary pull-right">确认新增</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<script>
    $(document).ready(function() {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
        //选择验证人得到电话号码
        $('#users input').on('ifChecked', function () {
            $('#mobile').val($(this).val());
            console.log($(this).data('name'));
        });

        //发送验证码
        $("#sendCheckCode").click(function () {
            var mobile = $("#mobile").val();
            if (mobile.trim().length<=0){
                console.log("手机号码为空!");
                swal("手机号码不能为空!","", "error");
                return false;
            }
            var This = this;
            $.post("${baseUrl}system/company/send",{mobile:$("#mobile").val()},function (result) {
                if(result =="success"){
                    //验证码发送成功...
                    time(This);
                }
                swal({
                    title:"验证码发送成功!",
                    timer:1000
                }).then(
                    function () {},
                    // handling the promise rejection
                    function (dismiss) {
                        if (dismiss === 'timer') {
                            console.log('I was closed by the timer')
                        }
                    }
                )
            });

        });

        //回车绑定
        $(".submit").keydown(function(event){
            if(event.which == "13")
                submit();
        });

        //提交
        $("#submit").click(function (){

            submit();
        });

        //提交
        function submit() {
            $.post("${baseUrl}system/company/check_code",
                {
                    checkCode: $("#checkCode").val()
                },
                function (result) {
                    debugger
                    if (result == "success") {
                        $.post("${baseUrl}system/company/onlineCompany",
                            {
                                id: $("#id").val(),
                                checkName: $("input[type='radio'][name='a']:checked").data('name')
                            },
                            function (result) {
                                debugger
                                if (result == "success") {
                                    swal("验证成功!", "该新企业ID为: " + $("#id").val() + " ,页面即将重新加载,请稍后...", "success");
                                    window.setTimeout(function () {
                                        window.location = '${baseUrl}system/company/list'
                                    }, 1000);
                                } else {
                                    swal({title: result});
                                }
                            }
                        );
                    } else {
                        swal({title: result});
                    }
                }
            );
        }

        var wait = 60;
        function time(o) {
            if (wait == 0) {
                o.removeAttribute("disabled");
                o.value = "发送验证码";
                wait = 60;
            } else {
                o.setAttribute("disabled", true);
                o.value = "重新发送(" + wait + ")";
                wait--;
                setTimeout(function () {
                    time(o)
                }, 1000)
            }
        }

    })
</script>
</@body.page>
</html>